#!/bin/bash
# 注意：这个只是测试数据库，没有加载数据库的过程，要配合在load_db.sh加载完对应数据库之后使用。
cd ../build

start_time=$(date +%s) # %s可以计算的是1970年以来的秒数

# Datasets (file)
#for dist in linear_64M linear_64Mseg1 linear_64Mseg10 norm_64M; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/sosd/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_llsm.txt
#    ./read_cold -f ../db/sosd/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_baseline.txt
#done

# idf_all
#for dist in idf_all; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/dataset/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_llsm.txt
#    ./read_cold -f ../db/dataset/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_baseline.txt
#done


#for dist in idf_758; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../index_parsed_txt/${dist}.txt -k 16 -v 64 -d ../ssd/db_${dist}_16_random -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_llsm.txt
#    ./read_cold -f ../index_parsed_txt/${dist}.txt -k 16 -v 64 -d ../ssd/db_${dist}_16_random -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_baseline.txt
#done

# idf_single_valid
#for dist in idf_575_valid idf_95_valid idf_175_valid idf_351_valid; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/ali_single_valid_index/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_llsm.txt
#    ./read_cold -f ../db/ali_single_valid_index/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/${dist}_16_baseline.txt
#done

#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_llsm.txt
#./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_llsm.txt
#./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/ar_16_baseline.txt
#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_llsm.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 8 -u -n 10000 -i 5 $* --change_level_load > ../evaluation/osm_16_baseline.txt


# Datasets (level)
#for dist in linear_64M linear_64Mseg1 linear_64Mseg10 norm_64M; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/sosd/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/${dist}_16_llsm_level.txt
#done

# idf_all
#for dist in idf_all; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/dataset/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/${dist}_16_llsm_level.txt
#done


#for dist in idf_758; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../index_parsed_txt/${dist}.txt -k 16 -v 64 -d ../ssd/db_${dist}_16_random -m 7 -u -n 10000 -i 5 $* > ../evaluation/${dist}_16_llsm_level.txt
#done

# ali idf single valid index
#for dist in idf_575_valid idf_95_valid idf_175_valid idf_351_valid; do
#    sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#    ./read_cold -f ../db/ali_single_valid_index/${dist}.txt -k 16 -v 64 -d ../ssd/db_ddist_${dist}_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/${dist}_16_llsm_level.txt
#done

#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/ar_16_llsm_level.txt
#./read_cold -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/db_ar_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/ar_16_llsm_level.txt
#
#sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/osm_16_llsm_level.txt
#./read_cold -f ../db/dataset/osm_ny.txt -k 16 -v 64 -d ../ssd/db_osm_16 -m 7 -u -n 10000 -i 5 $* > ../evaluation/osm_16_llsm_level.txt


data_path="$1"
data_name_=${data_path#*../}
data_name=${data_name_%.txt*}


sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
./read_cold_trace -f "$data_path" -k 16 -v 64 -d ../ssd/db_"$data_name" -m 7 -u -n 10000 -i 2 $* --change_level_load > ../evaluation/"$data_name"_16_llsm.txt
./read_cold_trace -f "$data_path" -k 16 -v 64 -d ../ssd/db_"$data_name" -m 8 -u -n 10000 -i 2 $* --change_level_load > ../evaluation/"$data_name"_16_baseline.txt

./read_cold_trace -f "$data_path" -k 16 -v 64 -d ../ssd/db_"$data_name" -m 7 -u -n 10000 -i 2 $* > ../evaluation/"$data_name"_16_llsm_level.txt

#-f ../111969901601639.txt -k 16 -v 64 -d ../ssd/db_111969901601639 -m 7 -u -n 10000 -i 2 $* --change_level_load > ../evaluation/111969901601639_16_llsm.txt
#-f ../111969901601639.txt -k 16 -v 64 -d ../ssd/db_111969901601639 -m 7 -u -n 10000 -i 5 $* > ../evaluation/111969901601639_16_llsm.txt

#./read_cold_trace -f ../db/dataset/amazon_reviews.txt -k 16 -v 64 -d ../ssd/amazon_reviews -m 7 -u -n 10000 -i 2 $* > ../evaluation/amazon_reviews_llsm.txt

cd ../learned-leveldb/
python ./scripts/collect_results.py 1 "$data_name"_16 > ../evaluation/expr_dataset_"$data_name"_16.txt
cat ../evaluation/expr_dataset_"$data_name"_16.txt

end_time=$(date +%s)
cost_time=$((end_time-start_time))
echo "$0" "运行时间：$((cost_time/60))min $((cost_time%60))s"